package com.zyc.app.woa.data;

import java.io.Serializable;

/**
 * Author: yingchang.zhang
 * Date  : 2014/11/27
 */
public class ArticleItem implements Serializable {
    public int id;
    public String title;
    public String url;
    public String imgLink;
    public String headImage;
    //    public String sourceName;
//    public String date;
//    public String lastModified;
    public String pageSize;

    public static ArticleItem parse(String xml) {
        ArticleItem articleItem = null;
        articleItem = new ArticleItem();
        articleItem.title = getElementValue(xml, "title");
        articleItem.url = getElementValue(xml, "url");
        articleItem.imgLink = getElementValue(xml, "imglink");
        articleItem.headImage = getElementValue(xml, "headimage");
//        articleItem.sourceName = getElementValue(xml, "sourcename");
//        articleItem.date = getElementValue(xml, "date");
        articleItem.pageSize = getElementValue(xml, "pagesize");
//        articleItem.lastModified = getElementValue(xml, "lastModified");
        return articleItem;
    }

    private static String getElementValue(String rawXml, String tag) {
        String[] values = XmlUtils.getElementsByTag(rawXml, tag);
        if (null != values && values.length > 0) {
            return XmlUtils.getElementText(values[0]);
        }
        return null;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("title: " + title + "\n");
        sb.append("url: " + url + "\n");
        sb.append("imgLink: " + imgLink + "\n");
        sb.append("headImage: " + headImage + "\n");
//        sb.append("sourceName: " + sourceName + "\n");
//        sb.append("date: " + date + "\n");
//        sb.append("lastModified: " + lastModified + "\n");
        sb.append("pageSize: " + pageSize + "\n");
        return sb.toString();
    }
}